<template>
  <div style="height: 100%;">
    <el-container style="height: 100%">
      <el-header style="padding: 0;z-index: 999">
        <el-menu
            mode="horizontal"
            background-color="#545c64"
            text-color="#fff"
            active-text-color="#ffd04b"
            router
            v-if="!isAdmin">

          <el-menu-item index="/home/first">首页</el-menu-item>
          <el-menu-item :key="index" v-for="(item,index) in rights" :index="item.router">{{item.name}}</el-menu-item>
          <el-menu-item index="/home/myInformation">个人中心</el-menu-item>
          <div class="title">
            图书电商平台
          </div>
        </el-menu>

        <el-menu
            mode="horizontal"
            router
            background-color="#545c64"
            text-color="#fff"
            active-text-color="#ffd04b"
            v-if="isAdmin">
          <el-menu-item index="/home/first">首页</el-menu-item>
          <el-menu-item index="/home/rightManagement">权限列表</el-menu-item>
          <el-menu-item index="/home/roleManagement">角色管理</el-menu-item>
          <el-menu-item index="/home/userManagement">用户管理</el-menu-item>
          <el-submenu index="/home">
            <template slot="title">数据报表</template>
            <el-menu-item index="/home/bookTypeMap">书籍分类</el-menu-item>
            <el-menu-item index="/home/userAgeMap">年龄分布</el-menu-item>
          </el-submenu>
          <div class="title">
            图书电商平台
          </div>
        </el-menu>
      </el-header>


      <el-main class="div_body">
        <router-view></router-view>
      </el-main>

      <el-footer>
        <a>京ICP备XXXXXXXX号  </a>
        <a>©2018-2022 北京图书管理能力有限公司</a>
      </el-footer>
    </el-container>

  </div>
</template>

<script>
export default {
  name: "HomePage",
  data(){
    return{
      isAdmin:false,
      tabListIndexes:[
        {name:"图书馆",router:"/home/library"},
        {name:"我的店铺",router:"/home/myStore"},
        {name:"购物车",router:"/home/cart"},
        {name:"个性推荐",router:"/home/recommend"},
        {name:"热点图书",router:"/home/hot"},
        {name:"我的订单",router:"/home/user"}
      ],
      rights:[]
    }
  },
  methods:{
  },
  async created() {
    this.isAdmin = this.$store.state.isAdmin;
    console.log("isadmin",this.isAdmin)
    let form = {
      token:window.sessionStorage.getItem("token")
    }

    const{data:res} = await this.$http.post("http://120.46.132.13:8081/api/role/getRoleRights",form)

    if(res.code===0||res.code===200){
      let array = res.data.showRights;
      for(let i=0; i<array.length; ++i){
        this.rights.push(this.tabListIndexes[array[i]-1])
      }
    }else{
      this.$notify.error(res.message);
    }
  }
}
</script>

<style scoped>
  .title{
    float: right;
    font-size: 35px;
    font-weight: 500;
    color: #ffffff;
    margin-top: 3px;
    margin-right: 25px
  }

  .el-header, .el-footer {
    background-color: #B3C0D1;
    color: #333;
    text-align: center;
    line-height: 60px;
  }

  .div_body{
    height: 100%;
    width: 100%;
  }


</style>
